package ds.queue;

import ds.linklist.firstlast.Link;
import ds.linklist.firstlast.LinkList;

public class LinkQueue {

	private LinkList theList;
	//---------------------------------
	public LinkQueue()
	{
		theList = new LinkList();
	}
	
	public void insert(int i)
	{
		theList.insertLast(i);
	}
	
	public int remove()
	{
		return theList.deleteFirst().getData();
	}
	
	public int peekFront() throws Exception
	{
		Link firstLink = theList.getFirst();
		if(firstLink!=null)
			return firstLink.getData();
		else
			throw new Exception("队列中尚无元素");
	}
	
	public boolean isEmpty()
	{
		return theList.isEmpty();
	}
	
	public void printQueue() {
		theList.displayList();
	}
}

class LinkQueueApp
{
	public static void main(String[] args) throws Exception
	{
		int i = 0;
		LinkQueue lq = new LinkQueue();
		lq.insert(i++);
		lq.insert(i++);
		lq.insert(i++);
		lq.insert(i++);
		lq.insert(i++);
		
		lq.peekFront();
		
		lq.printQueue();
		
		lq.remove();
		lq.remove();
		
		lq.printQueue();
	}
}
